<template>
  <!-- 抄送人节点 -->
  <div>
    {{view}}
  </div>
</template>

<script setup name="NotifyNode">
import {computed, getCurrentInstance, inject} from "vue";
import {KEY_PROCESS_DATA, KEY_VALIDATOR} from "../../config/keys"

const props = defineProps({
  tempNodeId: { // 临时节点ID
    type: String
  },
  node: { // 传入的流程配置数据
    type: Object,
    default: {}
  }
});

const { proxy } = getCurrentInstance();

// 获取流程数据
const processData = inject(KEY_PROCESS_DATA)
// 获取流程验证器实例
const validator = inject(KEY_VALIDATOR)

// 注册验证器
validator.register(props.tempNodeId, () => {
  let valid = true
  let message = "请选择抄送人"
  if (props.node.config.handlerScope === 1) {
    if (props.node.config.handlers.length === 0) {
      valid = false
    }
  }
  return {
    "valid": valid,
    "message": message
  }
})

const view = computed(()=> {
  let text = ""
  if (props.node.config.handlerScope === 1) {
    text = ""
    props.node.config.handlers.forEach(item => {
      text += item.label + " "
    })
  } else if (props.node.config.handlerScope === 2) {
    text = "部门主管"
  }
  if (text == null || text === "") {
    text = "请选择抄送人"
  }
  return text
})
</script>

<style lang="less" scoped>

</style>
